//
//  IntegralMallParticipateView.m
//  lmq
//
//  Created by 马田成 on 2017/4/2.
//  Copyright © 2017年 yuanxin. All rights reserved.
//

#import "IntegralMallParticipateView.h"

@interface IntegralMallParticipateView()
@end
@implementation IntegralMallParticipateView
- (void)awakeFromNib {
    [super awakeFromNib];
    self.number = 0;
    
    self.numberTextField.delegate = self;
    
    
    
    self.buttonOf5.layer.borderColor = [UIColor blackColor].CGColor;
    self.buttonOf5.layer.borderWidth = 1.0f;
    
    self.buttonOf10.layer.borderColor = [UIColor blackColor].CGColor;
    self.buttonOf10.layer.borderWidth = 1.0f;
    self.buttonOf15.layer.borderColor = [UIColor blackColor].CGColor;
    self.buttonOf15.layer.borderWidth = 1.0f;
    self.buttonOf20.layer.borderColor = [UIColor blackColor].CGColor;
    self.buttonOf20.layer.borderWidth = 1.0f;
    
    

    
//    [self.subtractButton setHidden:YES];
//    [self.addedButton setHidden:YES];
    
}
- (IBAction)jianButton:(UIButton *)sender {
    self.number =[self.numberTextField.text intValue];
    self.number -=1;
//    self.subtractAdd(self.number,NO);
    [self showOrderNumbers:self.number];
}
- (IBAction)addButton:(UIButton *)sender {
    
    self.number =[self.numberTextField.text intValue];
    self.number +=1;
    [self showOrderNumbers:self.number];
  //  self.subtractAdd(self.number,YES);

}
-(void)showOrderNumbers:(NSUInteger)count
{
    self.numberTextField.text = [NSString stringWithFormat:@"%lu",(unsigned long)self.number];
    NSInteger money = [self.numberTextField.text intValue];
    NSInteger money1 = [self.price intValue];
    NSInteger money3 = money * money1;
    NSString *str = [NSString stringWithFormat:@"%ld", (long)money3];
    self.allMoneyLabel.text = [str stringByAppendingString:@"积分"];
    
    
    if (self.number > 0)
    {
        [self.subtractButton setHidden:NO];
        [self.addedButton setHidden:NO];
    }
    else
    {
        [self.subtractButton setHidden:YES];
//        [self.addedButton setHidden:YES];
    }
//    if ([self.numberTextField.text intValue] > [self.numberLabel intValue]){
//        if ([self.numberTextField.text intValue] == 0) {
//    
//        [self.addedButton setHidden:YES];
//        [self.subtractButton setHidden:NO];
//        
//        }
//        else {
//        
//            [self.subtractButton setHidden:YES];
//            [self.addedButton setHidden:NO];
//            
//        }
//    }
//    else
//    {
//        [self.subtractButton setHidden:YES];
//        [self.addedButton setHidden:NO];
//    }
    
    
}
- (IBAction)fiveButton:(UIButton *)sender {
    
    if ([self.numberTextField.text intValue] == 0) {
         [self.subtractButton setHidden:YES];
    }
    
    else {
    if (sender.tag == 5) {
        if ([self.numberTextField.text intValue] >= [self.numberLabel intValue]){
            
        self.numberTextField.text = self.numberLabel;
        NSInteger money = [self.numberTextField.text intValue];
        NSInteger money1 = [self.price intValue];
        NSInteger money3 = money * money1;
        NSString *str = [NSString stringWithFormat:@"%ld", (long)money3];
            self.allMoneyLabel.text = [str stringByAppendingString:@"积分"];}
        else {
            self.numberTextField.text = @"5";
            NSInteger money = [self.numberTextField.text intValue];
            NSInteger money1 = [self.price intValue];
            NSInteger money3 = money * money1;
            NSString *str = [NSString stringWithFormat:@"%ld", (long)money3];
            self.allMoneyLabel.text = [str stringByAppendingString:@"积分"];
            
        }
        
    }else if (sender.tag == 10) {
    
        if ([self.numberTextField.text intValue] >= [self.numberLabel intValue]){
            
            self.numberTextField.text = self.numberLabel;
            NSInteger money = [self.numberTextField.text intValue];
            NSInteger money1 = [self.price intValue];
            NSInteger money3 = money * money1;
            NSString *str = [NSString stringWithFormat:@"%ld", (long)money3];
            self.allMoneyLabel.text = [str stringByAppendingString:@"积分"];}
        else {
            self.numberTextField.text = @"10";
            NSInteger money = [self.numberTextField.text intValue];
            NSInteger money1 = [self.price intValue];
            NSInteger money3 = money * money1;
            NSString *str = [NSString stringWithFormat:@"%ld", (long)money3];
            self.allMoneyLabel.text = [str stringByAppendingString:@"积分"];
            
        }

    
    }else if (sender.tag == 15) {
    
        if ([self.numberTextField.text intValue] >= [self.numberLabel intValue]){
            
            self.numberTextField.text = self.numberLabel;
            NSInteger money = [self.numberTextField.text intValue];
            NSInteger money1 = [self.price intValue];
            NSInteger money3 = money * money1;
            NSString *str = [NSString stringWithFormat:@"%ld", (long)money3];
            self.allMoneyLabel.text = [str stringByAppendingString:@"积分"];}
        else {
            self.numberTextField.text = @"15";
            NSInteger money = [self.numberTextField.text intValue];
            NSInteger money1 = [self.price intValue];
            NSInteger money3 = money * money1;
            NSString *str = [NSString stringWithFormat:@"%ld", (long)money3];
            self.allMoneyLabel.text = [str stringByAppendingString:@"积分"];
            
        }

    }else {
    
        if ([self.numberTextField.text intValue] >= [self.numberLabel intValue]){
            
            self.numberTextField.text = self.numberLabel;
            NSInteger money = [self.numberTextField.text intValue];
            NSInteger money1 = [self.price intValue];
            NSInteger money3 = money * money1;
            NSString *str = [NSString stringWithFormat:@"%ld", (long)money3];
            self.allMoneyLabel.text = [str stringByAppendingString:@"积分"];}
        else {
            self.numberTextField.text = @"20";
            NSInteger money = [self.numberTextField.text intValue];
            NSInteger money1 = [self.price intValue];
            NSInteger money3 = money * money1;
            NSString *str = [NSString stringWithFormat:@"%ld", (long)money3];
            self.allMoneyLabel.text = [str stringByAppendingString:@"积分"];
            
        }

    }
    
    
    }
}
- (void)textFieldDidEndEditing:(UITextField *)textField{
    
    if ([self.numberTextField.text intValue] > [self.numberLabel intValue]) {
        

        self.numberTextField.text = self.numberLabel;
//        self.numberTextField.enabled = false;
        NSInteger money = [self.numberTextField.text intValue];
        NSInteger money1 = [self.price intValue];
        NSInteger money3 = money * money1;
        NSString *str = [NSString stringWithFormat:@"%ld", (long)money3];
        self.allMoneyLabel.text = [str stringByAppendingString:@"积分"];
    }else {
    
    NSInteger money = [self.numberTextField.text intValue];
    NSInteger money1 = [self.price intValue];
    NSInteger money3 = money * money1;
    NSString *str = [NSString stringWithFormat:@"%ld", (long)money3];
    self.allMoneyLabel.text = [str stringByAppendingString:@"积分"];
    }
}
- (IBAction)NowPurchaseButton:(UIButton *)sender {
    if (self.block) {
        self.block(sender);
    }
    
    
    
}
- (void)callBackEditBlock:(EditBlcok)block{
    self.block = block;
}


@end
